package com.bd.module.salegood.dao.impl;

import java.sql.*;
import java.util.Vector;

import javax.swing.JOptionPane;

import com.bd.framework.utils.database.CheckConnection;
import com.bd.module.salegood.dao.SaleGoodDao;
import com.bd.module.salegood.pojo.Goods;

public class SaleGoodDaoImpl implements SaleGoodDao{
	private Vector v;        //存储搜寻到的数据库数据
	/**
	 * 这个方法将连接数据库，并把符合goodsMark参数的元组属性
	 * 存储在Goods中
	 * @param goodsMark
	 * @throws SQLException
	 */
	public boolean findGoodsByID(String goodsCode) {
		// TODO Auto-generated method stub
		Goods goods = new Goods();
		try {
			PreparedStatement state =new CheckConnection().getCheckConnection().prepareStatement("select g.GOODSCODE ,g.GOODSNAME , gp.RETAILPRICE  from INFO_GOODS g,INFO_GOODSPRICE  gp where gp.GOODSCODE=g.GOODSCODE  and gp.GOODSCODE=? and gp.MARKETCODE='0101'");
			state.setString(1,goodsCode);                   //给？设置参数
			ResultSet result = state.executeQuery();
			if(result.next()){
				goods.setGoodsCode(result.getString(1));
				goods.setGoodsName(result.getString(2));
				goods.setRetailprice(result.getDouble(3));
				goods.setGoodsNum(1);
				goods.setRate(1.0);
				goods.setMoney();
			//	System.out.println(goods.getGoodsCode()+" "+goods.getGoodsName());
				v = goods.getVector();
				state.close();
			}
			else{
				v=null;
				JOptionPane.showMessageDialog(null,"您输入的商品不存在或条码破损\n" 
						,"商品信息",JOptionPane.ERROR_MESSAGE);
				state.close();
				return false;
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return true;
	}

	/**
	 * 方法将返回获取数据后Vector对象
	 * @return
	 */
	public Vector getGoodsVector(){
		return v;
	}	

}
